package crm.model.studentPC.win;

import java.util.ArrayList;


import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;

import crm.model.studentPC.win.window.User32B;
import crm.model.studentPC.win.window.Window;

public class WindowList extends ArrayList<Window> {

	private User32B user32;

	public WindowList() {
		super();
		getWindows();

	}

	private ArrayList<Window> getWindows() {
		user32 = User32B.INSTANCE;
		user32.EnumWindows(new WNDENUMPROC() {
			public boolean callback(HWND hwnd, Pointer arg1) {

				User32B user32 = User32B.INSTANCE;
				Window f = new Window(hwnd, user32);
				if (!f.getName().equals("")
						&& !(f.getRectangle().width == 0
						&& f.getRectangle().width == 0
						&& f.getRectangle().x == 0 && f.getRectangle().y == 0)
						&& f.isVisible() && !(f.getName().equals("Start"))
						&& !(f.getName().equals("Program Manager"))) {

					add(f);
				}
				return true;
			}
		}, null);
		return this;
	}

	public void refresh() {
		clear();
		getWindows();

	}


	public Window getAktivWindow() {
		HWND hwnd = user32.GetForegroundWindow();
		Window w = new Window(hwnd, user32);
		return w;

	}
	public boolean deaktivateBlockInput(boolean flag){
		return user32.BlockInput(flag);
	}
}